﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace GameVLTK
{
    public class AvartarPlayer : VisibleGameEntity
    {
        //Nhân vật có được kích hoạt hay không
        private bool _IsActive;

        public bool IsActive
        {
            get { return _IsActive; }
            set { _IsActive = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_content"></param>
        /// <param name="_path"></param>
        /// <param name="_topLeft"></param>
        public AvartarPlayer(ContentManager _content, string _path, Vector2 _topLeft)
        {
            this.Sprites = new List<MySprite>();
            this.nSprites = 2;

            Texture2D[] txturesActive = LoadTextures(_content, _path + "Active/", 34);
            Texture2D[] txturesNonActive = LoadTextures(_content, _path + "Non Active/", 11);
        
            this.Size = new Vector2(txturesActive[0].Width, txturesActive[0].Height);
            this.TopLeft = _topLeft;

            MySprite mySpriteActive = new MySprite(txturesActive, _topLeft);
            MySprite mySpriteNonActive = new MySprite(txturesNonActive, _topLeft);
        

            mySpriteActive.FrameSequence = CalcFrameSeq(34);
            mySpriteNonActive.FrameSequence = CalcFrameSeq(11);
          

            this.Sprites.Add(mySpriteActive);
            this.Sprites.Add(mySpriteNonActive);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private int[] CalcFrameSeq(int max)
        {
            int[] frameSequence = new int[max];
            for (int i = 0; i < max; i++)
                frameSequence[i] = i;
                
            return frameSequence;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="_content"></param>
        /// <param name="_path"></param>
        /// <param name="_nTextures"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        private  Texture2D[] LoadTextures(ContentManager _content, string _path, 
                          int _nTextures)
        {
            Texture2D[] textures;
            textures = new Texture2D[_nTextures];

            for (int i = 0; i < _nTextures; i++)
            {
                textures[i] = _content.Load<Texture2D>(_path + (i + 1).ToString("00"));
            }
            return textures;
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            base.Draw(gameTime, spriteBatch);
        }
       
    }
}
